package com.gitee.andy.rpc.core;

import java.io.Serializable;

import com.gitee.andy.util.ProtostuffUtil;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MessageEncoder extends MessageToByteEncoder<Serializable> {

	@Override
	protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
		byte[] serialize = ProtostuffUtil.serialize(msg);
		out.writeInt(serialize.length).writeBytes(serialize);
	}

}
